package com.action;

import com.action.abs.AbstractBaseAction;
import com.vo.UploadMessageVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/form/*")
public class UploadAction extends AbstractBaseAction {
    @PostMapping("upload")
    public Object uploadHandler(UploadMessageVo uploadMessageVo, MultipartFile photo) {
        Map<String, Object> result = new HashMap<>(); // 保存最终的上传结果
        result.put("message", uploadMessageVo); // 普通对象
        result.put("photoName", photo.getName());
        result.put("photoOriginalFilename",photo.getOriginalFilename());
        result.put("photoContentType", photo.getContentType());
        result.put("photoSize", photo.getSize());
        return result;
    }

    //C:\Users\nfboy>curl -X POST -F "photo=@C:\develop\SpringBoot\gradle\kunming.png" -F "title=MuyanYootk" -F "content=www.yootk.com" -F "pubdate=2016-12-26" http://localhost:8082/test/form/upload
    //{"photoSize":453954,"message":{"title":"MuyanYootk","pubdate":"2016-12-25T16:00:00.000+00:00","content":"www.yootk.com"},"photoName":"photo","photoOriginalFilename":"kunming.png","photoContentType":"image/png"}
}
